<template>
  <div>
    <div class="show_tip clearfix">
      <section
        class="tip_txt tip_txt_qz"
        v-if="cashPopData.is_qz == 1"
        v-show="active == 3"
        ref="tx_qz"
      >
        <section class="name_tip" v-if="cashPopData.is_id_card">请填写真实姓名和身份证号码</section>
        <section class="name_tip" v-else>请填写真实姓名</section>
        <section class="balance_tip" v-if="cashPopData.commssion_to_balance_rate">
          本次提现为启征税服发放，提现金额为
          <span class="colored">{{qz_money}}</span>
        </section>
        <section class="counter_tip" v-if="cashPopData.withdraw_proportion">
          本次提现金额服务费为
          <span class="colored">{{qz_money}}</span>
        </section>
        <section class="actual_tip" v-if="cashPopData.withdraw_proportion">
          本次提现实发金额为
          <span class="colored">{{qz_money}}</span>
        </section>
      </section>
      <section
        v-else-if="cashPopData.is_gzll && cashPopData.release_level !=3"
        class="tip_txt tip_txt_wfx"
      >
        <section class="name_tip" v-if="cashPopData.is_id_card">请填写真实姓名和身份证号码</section>
        <section class="name_tip" v-else>请填写真实姓名</section>
        <div v-if="cashPopData.is_draw_int == 0 && cashPopData.withdraw_percentage > 0">
          <section class="name_tip">提现的最高金额是{{cashPopData.max_tx_money}}</section>
          <section class="name_tip">提现的最低金额是{{cashPopData.min_tx_money}}</section>
        </div>
        <div v-if="(isWithdrawType(2)||in_array(2)) && active == 2">
          <section class="balance_tip">
            本次提现转余额为
            <span class="colored">{{balance_fee}}元</span>(
            <b>{{this_num}}</b>
            *{{cashPopData.commssion_to_balance_rate}}%)
          </section>
          <section class="counter_tip" v-if="cashPopData.withdraw_proportion">
            本次提现扣除的手续费为
            <span class="colored">{{counter_fee}}元</span>(
            <b>{{cash_num}}</b>
            *{{cashPopData.withdraw_proportion}}%)
          </section>
        </div>
        <section v-if="cashPopData.withdraw_proportion && active != 2" class="counter_tip nowxgzll">
          本次提现扣除的手续费为
          <span class="colored">{{counter_fee}}元</span>(
          <b>{{cash_num}}元</b>
          *
          {{cashPopData.release_level == 1 ?cashPopData.min_withdraw_proportion:cashPopData.max_withdraw_proportion}}%)
        </section>
      </section>
      <!-- 见证宝 -->
      <section v-else-if="cashPopData.jzb_is_opened==1" class="tip_txt tip_txt_wfx">
        <div v-if="cashPopData.is_draw_int == 0 && cashPopData.withdraw_percentage > 0">
          <section class="name_tip">提现的最高金额是{{cashPopData.max_tx_money}}</section>
          <section class="name_tip">提现的最低金额是{{cashPopData.min_tx_money}}</section>
        </div>
        <!-- <section class="counter_tip" v-if="cashPopData.withdraw_proportion">
          对公账户提现手续费：
          <span class="colored">{{counter_fee_company}}元</span> -->
          <!-- <b>{{cash_num}}元</b>
          *{{cashPopData.withdraw_proportion}}%+{{jzb_fee}}) -->
        <!-- </section> -->
        <section class="counter_tip" v-if="cashPopData.withdraw_proportion">
          个人账户提现手续费：
          <span class="colored">{{counter_fee_personal}}元</span>
        </section>
      </section>
      <section v-else class="tip_txt tip_txt_wfx">
        <section class="name_tip" v-if="cashPopData.is_id_card">请填写真实姓名和身份证号码</section>
        <section class="name_tip" v-else>请填写真实姓名</section>
        <div v-if="cashPopData.is_draw_int == 0 && cashPopData.withdraw_percentage > 0">
          <section class="name_tip">提现的最高金额是{{cashPopData.max_tx_money}}</section>
          <section class="name_tip">提现的最低金额是{{cashPopData.min_tx_money}}</section>
        </div>
        <section class="balance_tip" v-if="cashPopData.commssion_to_balance_rate">
          本次提现转余额为
          <span class="colored">{{balance_fee}}元</span>(
          <b>{{this_num}}元</b>
          *{{cashPopData.commssion_to_balance_rate}}%)
        </section>
        <section class="counter_tip" v-if="cashPopData.withdraw_proportion">
          本次提现扣除的手续费为
          <span class="colored">{{counter_fee}}元</span>(
          <b>{{cash_num}}元</b>
          *{{cashPopData.withdraw_proportion}}%)
        </section>
        <section class="counter_tip" v-if="cashPopData.is_withdraw_point_dz">
          本次提现额外扣除的积分为
            <span class="colored" >{{withdraw_point_fee}}</span>(
            <b>{{money||"0.00"}}{{is_crossBorderDz? mSymbol.name:'元'}}</b>
            *{{cashPopData.withdraw_point_proportion}}%)
        </section>
      </section>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
export default Vue.extend({
  props: {
    dzData: {
      type: Object,
      default: () => {
        const Obj = {
          isYun_dz: false,
          is_store_tx_dz: null,
          store_info_dz: null
        }
        return Obj
      }
    },
    cashPopData: Object,
    money: {
      type: [Number, String],
      default: 0
    },
    isWithdrawType: {
      type: Function,
      default: null
    },
    in_array: {
      type: Function,
      default: null
    },
    active: [Number, String]
  },
  data() {
    return {
      qz_money: '0.00元',
      balance_fee: '0.00',
      this_num: '0.00',
      counter_fee: '0.00',
      cash_num: '0.00',
      service_charge: {}, // 见证宝平安银行手续费计算规则
      counter_fee_company: '0.00', // 对公账户
      counter_fee_personal: '0.00' // 个人账户
    }
  },
  computed: {
    // counter_fee() {
    //   let num = this.money * (this.cashPopData.withdraw_proportion / 100)
    //   num = num || 0
    //   return num.toFixed(2)
    // }
    withdraw_point_fee() {
      let num = this.money * (this.cashPopData.withdraw_point_proportion / 100)
      num = num || 0
      return Math.round(num)
    }
  },
  methods: {
    qzServiceCharge() {
      const is_qz_show = this.$refs.tx_qz
      if (!is_qz_show) return false
      this.qz_money = '0.00元'
      if (!this.money) return false
      // qzServiceCharge().then(res => {
      //   this.$loadingWrap.close()
      //   if (res.status == 1) {
      //   } else {
      //     this.$Error(res.msg)
      //   }
      // })
      // console.log('启征费用计算')
    }
  },
  created() {
    this.service_charge = this.cashPopData.service_charge
  },
  watch: {
    money(val) {
      this.qzServiceCharge()
      let counter_fee
      let cash_num = +this.money
      let balance_fee
      let this_num
      // 计算转余额
      if (
        this.cashPopData.commssion_to_balance_rate > 0 &&
        (!this.cashPopData.is_gzll || this.cashPopData.active == 2)
      ) {
        counter_fee = cash_num * (this.cashPopData.withdraw_proportion / 100) // 手续费
        this_num = cash_num - counter_fee
        balance_fee =
          this_num *
          parseFloat(this.cashPopData.commssion_to_balance_rate / 100) // 转余额的金额
        // 提现转余额部分不扣手续费 @cyh
        if (this.cashPopData.is_commssion_to_balance_withdraw < 1) {
          balance_fee =
            cash_num * (this.cashPopData.commssion_to_balance_rate / 100)
          this_num = cash_num
        }
        this.balance_fee = balance_fee.toFixed(2)
        this.this_num = this_num.toFixed(2)
      } else if (this.cashPopData.is_gzll && this.active != 2) {
        if (this.cashPopData.release_level == 1) {
          counter_fee =
            cash_num *
            (this.cashPopData.min_withdraw_proportion / 100) // 手续费
        } else if (this.cashPopData.release_level == 2) {
          counter_fee =
            cash_num *
            (this.cashPopData.max_withdraw_proportion / 100) // 手续费
        } else {
          this.$Error('该用户本月提现额度已满')
          return false
        }
      } else if (this.cashPopData.jzb_is_opened == 1) {
        counter_fee = cash_num * (this.cashPopData.withdraw_proportion / 100)
        const new_cash_num = cash_num - counter_fee
        if (new_cash_num > 0) {
          // 对公账户 counter_fee_company
          if (new_cash_num > 50000) {
            this.counter_fee_company = counter_fee + 8
          } else {
            this.counter_fee_company = counter_fee + 5
          }
          // 个人账户 counter_fee_personal
          if (new_cash_num > 50000) {
            this.counter_fee_personal = counter_fee + 25
          } else if (new_cash_num >= 1000 && cash_num <= 50000) {
            this.counter_fee_personal = counter_fee + 12.5
          } else {
            this.counter_fee_personal = counter_fee + 0.5
          }
        }
        if (val) {
          this.counter_fee_company = this.counter_fee_company ? Number(this.counter_fee_company).toFixed(2) : '0.00'
          this.counter_fee_personal = this.counter_fee_personal ? Number(this.counter_fee_personal).toFixed(2) : '0.00'
        } else {
          this.counter_fee_company = '0.00'
          this.counter_fee_personal = '0.00'
        }
      } else {
        counter_fee = cash_num * (this.cashPopData.withdraw_proportion / 100) // 手续费
      }
      // 计算手续费
      counter_fee = counter_fee || 0
      if (
        this.cashPopData.is_commssion_to_balance_withdraw < 1 &&
        this.cashPopData.is_gzll == 0
      ) {
        balance_fee = balance_fee || 0
        counter_fee =
          (cash_num - balance_fee) *
          parseFloat(this.cashPopData.withdraw_proportion / 100)
        cash_num = cash_num - balance_fee
      }
      this.counter_fee = counter_fee.toFixed(2)
      this.cash_num = cash_num.toFixed(2)
    }
  }
})
</script>

<style lang="scss">
.show_tip {
  padding: 20px 30px;
  // background-color: #fafafa;
  .tip_txt {
    display: block;
    font-size: 24px;
    line-height: 44px;
    color: #999;
    .colored {
      color: #ff0909;
    }
  }
}
</style>